package com.selfdriving.wl.activity;

import java.util.List;

import net.tsz.afinal.annotation.view.ViewInject;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import com.selfdriving.BaseApplication;
import com.selfdriving.R;
import com.selfdriving.activity.GroupMessageActivity;
import com.selfdriving.adapter.NearbyFriendAdapter;
import com.selfdriving.bean.User;

public class MyTravel {
	View view;
	BaseApplication application;
	Context context;

	ListView friend_list;

	private NearbyFriendAdapter adapter;

	private List<User> users;
	
	LayoutInflater inflater;


	public MyTravel(BaseApplication application, Context context,
			OnClickListener onClickListener, List<User> users) {
		inflater = LayoutInflater.from(context);
		view = inflater.inflate(R.layout.nearby_friend, null);
		this.application = application;
		this.context = context;
		this.users = users;
		initViews();
	}

	public void initViews() {
		friend_list = (ListView) view.findViewById(R.id.friend_list);

		adapter = new NearbyFriendAdapter(context, users);

		friend_list.setAdapter(adapter);

		friend_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (arg2 == 0) {
					return;
				}
				Intent intent = new Intent(context, GroupMessageActivity.class);
				context.startActivity(intent);
			}
		});
		
		friend_list.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				boolean isEdit = adapter.getEdit();
				adapter.setEdit(!isEdit);
				adapter.notifyDataSetChanged();
				return false;
			}
		});
	}

	public View getView() {
		return view;
	}

}
